home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MIDICraft's MIDINET CD-ROM
/
MIDICraft's MIDINET CD-ROM.iso
/
DOSUTILS
/
KORG
/
GETDUMP.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1996-11-01
|
4KB
|
225 lines
// getdump: decode korg dump
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include "sb.hpp"
#include "filei3.hpp"
Soundcard* card = 0;
FILE* f = 0;
int raw = 0;
int decodeany = 0;
unsigned char buf[32000];
int buflen = 0;
long skip = 0;
void flushbuf()
{
if (buflen > 0)
if (fwrite(buf, buflen, 1, f) != 1)
fprintf(stderr, "write error\n");
buflen = 0;
}
void add(FILE* f, unsigned char* s, int len, int encoded)
{
if (buflen + 7 > sizeof(buf))
flushbuf();
if (encoded)
len = code8to7(s, len, buf+buflen);
else
{
memcpy(buf+buflen, s, len);
}
if (len > 0)
buflen += len;
}
int hear()
{
card->reset();
unsigned char c;
int ret = 0;
fprintf(stderr, "send any dump from korg i3:\n");
card->startinput();
int record = 0;
unsigned char dumpdata[8];
unsigned char head[5];
char filename[14];
int dumplen = 0;
int headlen = 0;
int func = 0;
int encoded = 0;
char* typ = 0;
f = 0;
while (!kbhit() || getch() != 27)
{
int count = card->hear(&c, 1);
if (count <= 0)
continue;
ret = 1;
if (!record)
{
if (c == 0xF0)
{
record = 1;
head[0] = c;
headlen = 1;
}
// ignore
continue;
}
// recording
if (headlen > 0 && head[0] == 0xf0 && headlen < 5)
{
if (headlen < 5)
head[headlen++] = c;
if (headlen == 5)
{
printf("F0 %02X %02X %02X %02X ... ",
head[1], head[2], head[3], head[4]);
func = c;
skip = 0;
encoded = 1;
typ = 0;
switch(c)
{
case 0x40: break;
case 0x4c: typ = "prg"; break;
case 0x64: typ = "arr"; break;
case 0x65: typ = "sty"; break;
case 0x48: skip = 2; typ = "sng"; break;
case 0x39: break;
case 0x51: typ = "glb"; break;
case 0x52: typ = "dkt"; break;
case 0x50: skip = 4, typ = "all"; break;
case 0x66: skip = 2; typ = "bsq"; break;
default:
encoded = 0;
break;
}
if (decodeany)
{
encoded = 1;
}
if (raw)
{
skip = 0;
encoded = 0;
}
flushbuf();
dumplen = 0; // data starts
if (typ)
sprintf(filename, "dump%s.dat", typ);
else
sprintf(filename, "dump%02X.dat", func);
f = fopen(filename, "wb");
if (!f)
{
perror(filename);
return 0;
}
}
continue;
}
if (c == 0xf7)
{
if (f && dumplen > 0)
add(f, dumpdata, dumplen, encoded);
dumplen = 0;
flushbuf();
fclose(f); f = 0;
printf("F7\t");
switch(func)
{
case 0x41: printf("parameter change\n"); break;
case 0x48: printf("all song data dump\n"); break;
case 0x4c: printf("all program data dump\n"); break;
case 0x4e: printf("mode change %d\n", dumpdata[0]); break;
case 0x52: printf("drumkit data dump\n"); break;
case 0x51: printf("global data dump\n"); break;
case 0x50: printf("all data dump\n"); break;
case 0x53: printf("drumkit parameter change\n"); break;
case 0x64: printf("all arrangement data dump\n"); break;
case 0x65: printf("all style data dump\n"); break;
case 0x66: printf("all backing sequence data dump\n"); break;
default:
printf("unknown sysex\n");
break;
}
record = 0;
headlen = 0;
continue;
}
if (skip > 0)
{
add(f, &c, 1, 0);
skip--;
}
else
{
dumpdata[dumplen++] = c;
if (dumplen >= 8)
{
if (f)
add(f, dumpdata, dumplen, encoded);
dumplen = 0;
}
}
}
if (f)
{
if (dumplen > 0)
add(f, dumpdata, dumplen, encoded);
flushbuf();
fclose(f); f = 0;
}
card->stopinput();
return ret;
}
int main(int argc, char** argv)
{
argc--; argv++;
while (argc > 0 && **argv == '-')
{
if (strnicmp(*argv, "-raw", 4) == 0)
{
raw = 1;
argc--; argv++;
continue;
}
if (strnicmp(*argv, "-decode", 2) == 0)
{
decodeany = 1;
argc--; argv++;
continue;
}
fprintf(stderr, "invalid option %s\n", *argv);
argc--; argv++;
}
card = detect_soundcard();
if (!card)
{
fprintf(stderr, "Could not detect soundcard\n");
return 1;
}
if (!hear())
fprintf(stderr, "no response from soundcard\n");
delete card;
return 0;
}